package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.DaoFactory;
import dao.UserDao;
import entity.User;

public class Cascade_user extends HttpServlet {
	@Override
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=utf-8");
		PrintWriter out = response.getWriter();
		out.println("<users>");
		UserDao dao = DaoFactory.getInstance(UserDao.class);
		try {
			List<User> list = dao.findAll();
			for (User u : list) {
				out.println("<user>");
				out.println("<id>" + u.getId() + "</id>");
				out.println("<username>" + u.getUserName() + "</username>");
				out.println("</user>");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		out.println("</users>");
		out.flush();
		out.close();
	}
}
